home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Why doesn't this work?
- Date: Tue, 05 Mar 96 12:54:12 GMT
- Organization: none
- Message-ID: <826030452snz@genesis.demon.co.uk>
- References: <1996Mar4.161412.137442@forest>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1996Mar4.161412.137442@forest> ebromber@forest.drew.edu writes:
-
- ...
-
- > main();
- > {
-
- This is a syntax error and won't compile (at least not without an error).
- Remove the ;
-
- ...
-
- > while (c=getch() !='\n')
- > { count++;
- > pass[count]=c;
-
- You should store the character before you increment count. As it stands
- this stores characters in pass[1] through to pass[4].
-
- ...
-
- > if (real[i]=pass[i]) error++;
-
- Make that:
-
- if (real[i]==pass[i]) error++;
-
- Many compilers can warn you about this if you set an appropriate warning
- level. Also note that the entire comparison loop can be replaced with a
- single memcmp() call.
-
- > if (error>0) {printf("\nWRONG PASSWORD\n"); main();}
-
- Every time the user gets the password wrong you'll eat up more stack space
- (unless your compiler can optimise tail end recursion). Use a loop instead.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-